package org.example.DAO;

import org.example.Book;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository(value="bookDaoImpl")
public class BookDAOImpl extends AbstractBookDAO {

    @Override
    public void insertBook(Book book) {
        super.insertBook(book);
        String INSERT_BOOK="INSERT INTO book(isdn,name,price) VALUES(?,?,?)";
        Object[] args={book.getIsdn(),book.getName(),book.getPrice()};
        jdbcTemplate.update(INSERT_BOOK,args);

    }
    @Override
    public void modifyBook(Book book) {
        super.modifyBook(book);
        String MODIFY_BOOK="update book set price=?";
        Object[] args={book.getPrice()};
        jdbcTemplate.update(MODIFY_BOOK,args);

    }
    public List<Book> queryAll() {
        String QUERY_ALL_BOOK="select*from book";//定义一个基础的sql查询语句
        RowMapper<Book> rowMapper=new BeanPropertyRowMapper<Book>(Book.class);
        books=jdbcTemplate.query(QUERY_ALL_BOOK,rowMapper);
        return books;
    }


}
